# -*- coding: utf-8 -*- # Sprout for Kids XBMC Addon import sys import httplib import urllib, urllib2, cookielib, datetime, time, re, os, string import xbmcplugin, xbmcgui, xbmcaddon, xbmcvfs, xbmc import cgi, gzip from StringIO import StringIO USER_AGENT = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25' GENRE_TV = "TV" UTF8 = 'utf-8' MAX_PER_PAGE = 25 SPROUTBASE = 'http://www.sproutonline.com%s' addon = xbmcaddon.Addon('plugin.video.sprout') __addonname__ = addon.getAddonInfo('name') __language__ = addon.getLocalizedString home = addon.getAddonInfo('path').decode(UTF8) icon = xbmc.translatePath(os.path.join(home, 'icon.png')) addonfanart = xbmc.translatePath(os.path.join(home, 'fanart.jpg')) def log(txt): message = '%s: %s' % (__addonname__, txt.encode('ascii', 'ignore')) xbmc.log(msg=message, level=xbmc.LOGDEBUG) def cleanfilename(name): valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) return ''.join(c for c in name if c in valid_chars) def demunge(munge): try: munge = urllib.unquote_plus(munge).decode(UTF8) except: pass return munge def deuni(a): a = a.replace(''',"'") a = a.replace('&','&') a = a.replace(''',"'") return a def getRequest(url): log("getRequest URL:"+str(url)) headers = {'User-Agent':USER_AGENT, 'Accept':"text/html", 'Accept-Encoding':'gzip,deflate,sdch', 'Accept-Language':'en-US,en;q=0.8'} req = urllib2.Request(url.encode(UTF8), None, headers) try: response = urllib2.urlopen(req) if response.info().getheader('Content-Encoding') == 'gzip': log("Content Encoding == gzip") buf = StringIO( response.read()) f = gzip.GzipFile(fileobj=buf) link1 = f.read() else: link1=response.read() except: link1 = "" link1 = str(link1).replace('\n','') return(link1) def getSources(fanart): urlbase = SPROUTBASE % ('/videos/shows/') pg = getRequest(urlbase) blob = re.compile('